package com.tch.aop;

import java.util.Arrays;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;



@Aspect
@Component
public class DoException {


@Around("execution(* com.tch.*.*.*(..))")
public void logException(ProceedingJoinPoint pjd){
	Object result = null;
	String methodName = pjd.getSignature().getName();
	Class targetClass=pjd.getTarget().getClass();
	try { 
		//前置֪
		//System.out.println("  The method " + methodName + " begins with " + Arrays.asList(pjd.getArgs()));
		result = pjd.proceed();
		//后置֪
		//System.out.println("The method " + methodName + " ends with " + result);
	} catch (Throwable e) {
		Logger logger = LoggerFactory.getLogger(targetClass);
		logger.error(e.getMessage(),e);
		//异常֪
		//System.out.println("The method " + methodName + " occurs exception:" + e);
		throw new RuntimeException(e);
	}
	//֪finally
	//System.out.println("The method " + methodName + " ends");
	
}
}
